package org.elsfs.cloud.common.mybatis.ext.sql.support.select;

import lombok.RequiredArgsConstructor;
import org.elsfs.cloud.common.mybatis.ext.sql.SqlFragment;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 聚合选择项
 *

 */
@RequiredArgsConstructor
public class CompositeSelectItem implements SelectItem {

    /**
     * 选择项列表
     */
    private final List<SelectItem> selectItems;

    /**
     * 构建SQL片段
     *
     * @return SQL片段
     */
    @Override
    public String buildSqlFragment() {
        return String.format(
            "SELECT %s",
            this.selectItems.stream()
                .map(SqlFragment::buildSqlFragment)
                .collect(Collectors.joining(", "))
        );
    }
}
